package com.xckj.cycling.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.xckj.cycling.R;
import com.xckj.cycling.framework.BaseFragmentKt;
import com.xckj.cycling.view.CWebView;

/**
 * webview 的基础类
 */
public abstract class BaseWebViewFragment extends BaseFragmentKt {

    @Nullable
    protected CWebView webView = null;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        CWebView cWebView = (CWebView) inflater.inflate(R.layout.fragment_base_webview, container, false);
        String url = getUrl();
        if (!TextUtils.isEmpty(url)) {
            cWebView.loadUrl(getUrl());
        }
        initWebView(cWebView);
        webView = cWebView;
        return cWebView;
    }

    protected void initWebView(CWebView webView) {

    }

    /**
     * 返回与H5交互的 js 实例
     *
     * @return
     */
    protected abstract Object getJsAction();


    /**
     * 返回默认加载的url
     *
     * @return
     */
    @Nullable
    protected abstract String getUrl();

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    public boolean listenLocation() {
        return false;
    }
}
